<template>
  <view class="work-city">
    <up-navbar :leftIconSize="40" @rightClick="rightClick" :autoBack="true">
      <template #center>
        <view class="u-nav-slot">
          <view class="page-title">
            <text>重庆</text>
            <up-icon name="arrow-down-fill" color="#1c1c1c" size="20"></up-icon>
          </view>
        </view>
      </template>
    </up-navbar>
    <view class="main" :class="platformClass">
      <view class="main-box">
        <!-- 商圈与地铁栏 -->
        <view class="_box-left">
          <view
            class="filter-type"
            v-for="(item, index) in filterTypeList"
            :key="index"
            :class="typeActive == item.id ? 'filter-type-on' : ''"
            @tap="typeCheck(item)"
          >
            <view class="_type-content"
              ><text>{{ item.type }}</text></view
            ></view
          >
        </view>

        <!-- 右侧选择区 -->
        <view class="_box-right">
          <!-- 商圈内容选择 -->
          <template v-if="typeActive == 1">
            <view class="_right-1">
              <scroll-view :scroll-y="true" class="scroll-right-1">
                <view
                  class="_right-1-item"
                  v-for="(item, index) in filterTypeList[0].list"
                  :key="index"
                  @tap="filterTypeChoose(filterTypeList[0], item)"
                  ><view
                    class="_right-item-name"
                    :class="
                      filterTypeList[0].chooseList.includes(item)
                        ? '_right-item-name-on'
                        : ''
                    "
                    ><text>{{ item }}</text></view
                  ></view
                >
              </scroll-view>
            </view>
            <view class="_right-2">
              <scroll-view :scroll-y="true" class="scroll-right-2">
                <view
                  class="_right-2-item"
                  v-for="(item, index) in filterTypeList[0].businessList[
                    filterTypeList[0].list.findIndex(
                      (i) => i == filterTypeList[0].chooseList[0]
                    )
                  ]"
                  :key="index"
                  ><view class="_right-item-name"
                    ><text>{{ item }}</text></view
                  ></view
                >
              </scroll-view>
            </view>
          </template>

          <!-- 地铁内容选择 -->
          <template v-if="typeActive == 2">
            <view class="_right-1">
              <scroll-view :scroll-y="true" class="scroll-right-1">
                <view class="_right-a-item"><text>全重庆</text></view>
                <view
                  class="_right-metro-item"
                  v-for="(item, index) in 18"
                  :key="index"
                >
                  <view class="_metro-item-line"></view>
                  <view class="_metro-item-name"
                    ><text>{{ item }}号线</text></view
                  >
                </view>
              </scroll-view>
            </view>
            <view class="_right-2">
              <scroll-view
                :scroll-y="true"
                class="scroll-right-2 scroll-right-b"
              >
                <view
                  class="_right-b-item"
                  v-for="(item, index) in 30"
                  :key="index"
                  ><view class="_right-item-name"
                    ><text>全重庆</text></view
                  ></view
                >
              </scroll-view>
            </view>
          </template>
        </view>
      </view>
    </view>

    <view class="footer">
      <view class="footer-btn _btn-cancel" @tap="chooseCancel"
        ><text>清除</text></view
      >
      <view class="footer-btn _btn-confirm" @tap="chooseConfirm"
        ><text>确定</text></view
      >
    </view>
  </view>
</template>

<script setup>
import { ref } from "vue";
import { onLoad } from "@dcloudio/uni-app";
// 定义方法
const rightClick = () => {
  console.log("rightClick");
};

const leftClick = () => {
  console.log("leftClick");
};

const platformClass = ref("");
onLoad(() => {
  const systemInfo = uni.getSystemInfoSync();
  // console.log("systemInfo", systemInfo);
  if (systemInfo.osName === "android") {
    platformClass.value = "main-android-style";
  } else if (systemInfo.osName === "ios") {
    platformClass.value = "main-ios-style";
  }
});

// 定义左侧数据
const filterTypeList = ref([
  {
    id: 1,
    type: "商圈",
    list: [
      "重庆",
      "渝中区",
      "渝北区",
      "沙坪坝区",
      "九龙坡区",
      "大渡口区",
      "南岸区",
      "巴南区",
      "北碚区",
    ],
    chooseList: ["重庆"],
    isRadio: true, // 城市是否单选
    businessList: [
      ["全重庆"],
      ["渝中区1", "渝中区2", "渝中区3"],
      ["渝北区1", "渝北区2", "渝北区3"],
      ["沙坪坝区1", "沙坪坝区2", "沙坪坝区3"],
      ["九龙坡区1", "九龙坡区2", "九龙坡区3"],
      ["大渡口区1", "大渡口区2", "大渡口区3"],
      ["南岸区1", "南岸区2", "南岸区3"],
      ["巴南区1", "巴南区2", "巴南区3"],
      ["北碚区1", "北碚区2", "北碚区3"],
    ],
    choosebusinessList: [], // 已选二级商圈
  },
  {
    id: 2,
    type: "地铁",
  },
]);

// 定义左侧选中变量
const typeActive = ref(1);

// 左侧筛选类型选择事件
function typeCheck(item) {
  typeActive.value = item.id;
}

// 定义右侧选择事件
function filterTypeChoose(item, item2) {
  if (item.isRadio) {
    item.chooseList = [];
    item.chooseList = [item2];
  } else {
    if (item.chooseList.includes(item2)) {
      item.chooseList.splice(item.chooseList.indexOf(item2), 1);
    } else {
      item.chooseList.push(item2);
    }
  }
}

function chooseCancel() {
  console.log("chooseCancel");
}

function chooseConfirm() {
  console.log("chooseConfirm");
}
</script>

<style lang="scss" scoped>
.work-city {
  width: 100%;

  .page-title {
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: center;
    color: #1c1c1c;
  }

  .main {
    width: 100%;

    .main-box {
      width: 100%;
      height: 100%;
      display: flex;
      flex-wrap: nowrap;
      justify-content: space-between;

      ._box-left {
        width: 190rpx;
        height: 100%;
        border-right: 1px solid #ececec;

        .filter-type {
          width: 100%;
          margin-top: 44rpx;
          margin-bottom: 18rpx;
          display: inline-block;

          ._type-content {
            font-weight: 400;
            font-size: 32rpx;
            color: #000000;
            border-left: 6rpx solid #ffffff;
            padding-left: 20rpx;
            display: inline-block;
            transition: all 0.3s;
          }
        }

        .filter-type-on {
          ._type-content {
            color: #1872ff;
            border-left: 6rpx solid #1872ff;
            transition: all 0.3s;
          }
        }

        .filter-type:last-child {
          padding-bottom: 146rpx;
        }
      }

      ._box-right {
        width: calc(100% - 192rpx);
        height: 100%;
        display: flex;
        flex-wrap: nowrap;
        justify-content: flex-start;

        ._right-1 {
          height: 100%;

          .scroll-right-1 {
            width: 268rpx;
            height: 100%;
            overflow: auto;

            ._right-1-item {
              width: 240rpx;
              height: 68rpx;
              margin-top: 20rpx;
              margin-left: 28rpx;
              display: inline-block;
              margin-bottom: 10rpx;
            }

            ._right-1-item:last-child {
              padding-bottom: 234rpx;
            }

            ._right-a-item {
              width: 240rpx;
              height: 68rpx;
              font-size: 36rpx;
              font-weight: 400;
              color: #1c1c1c;
              line-height: 68rpx;
              text-align: center;
              margin-top: 20rpx;
              margin-left: 28rpx;
              display: inline-block;
            }

            ._right-metro-item {
              width: max-content;
              display: flex;
              flex-wrap: nowrap;
              justify-content: flex-start;
              align-items: center;
              margin-top: 28rpx;
              margin-left: 66rpx;
              line-height: 68rpx;

              ._metro-item-line {
                width: 24rpx;
                height: 12rpx;
                background-color: #397eb2;
                border-radius: 50rpx;
              }

              ._metro-item-name {
                font-size: 36rpx;
                font-weight: 400;
                color: #1c1c1c;
                width: 178rpx;
                word-break: break-all;
                margin-left: 12rpx;
              }
            }

            ._right-metro-item:last-child {
              padding-bottom: 146rpx;
            }

            ._right-item-name {
              background-color: #f6f6f6;
              border-radius: 8rpx;
              border: 1px solid #f6f6f6;
              font-size: 36rpx;
              font-weight: 400;
              color: #1c1c1c;
              line-height: 68rpx;
              text-align: center;
              transition: all 0.3s;
            }

            ._right-item-name-on {
              color: #1872ff;
              background-color: #ffffff;
              border: 1px solid #1872ff;
              transition: all 0.3s;
            }
          }
        }

        ._right-2 {
          height: 100%;

          .scroll-right-2 {
            width: 248rpx;
            height: 100%;
            overflow: auto;

            ._right-2-item {
              width: 240rpx;
              height: 68rpx;
              margin-top: 20rpx;
              margin-left: 20rpx;
              display: inline-block;
              margin-bottom: 10rpx;
            }

            ._right-2-item:last-child {
              padding-bottom: 234rpx;
            }

            ._right-b-item {
              width: 240rpx;
              height: 68rpx;
              font-size: 36rpx;
              font-weight: 400;
              color: #1c1c1c;
              line-height: 68rpx;
              text-align: center;
              margin-top: 20rpx;
              margin-left: 20rpx;
              display: inline-block;

              ._right-item-name {
                background-color: #ffffff;
                border-radius: 8rpx;
                border: 1px solid #ffffff;
                font-size: 36rpx;
                font-weight: 400;
                color: #1c1c1c;
                line-height: 68rpx;
                text-align: center;
              }
            }

            ._right-b-item:last-child {
              padding-bottom: 234rpx;
            }

            ._right-item-name {
              background-color: #f6f6f6;
              border-radius: 8rpx;
              border: 1px solid #f6f6f6;
              font-size: 36rpx;
              font-weight: 400;
              color: #1c1c1c;
              line-height: 68rpx;
              text-align: center;
            }
          }

          .scroll-right-b {
            width: 260rpx;
          }
        }
      }
    }
  }

  .main-android-style {
    // height: calc(100vh - 96rpx);
    height: 100vh;
    padding-top: 136rpx;
  }

  .main-ios-style {
    // height: calc(100vh - 88rpx);
    height: 100vh;
    padding-top: 176rpx;
  }

  .footer {
    width: 100%;
    height: 146rpx;
    background-color: #ffffff;
    position: fixed;
    left: 0;
    bottom: 0;
    z-index: 2;
    border-top: 1px solid #ececec;
    box-sizing: border-box;
    padding: 32rpx 28rpx 22rpx;
    display: flex;
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: center;

    .footer-btn {
      height: 92rpx;
      border-radius: 8rpx;
      font-size: 36rpx;
      font-weight: 400;
      text-align: center;
      line-height: 92rpx;
    }

    ._btn-cancel {
      width: 244rpx;
      background-color: #ececec;
      color: #1c1c1c;
    }

    ._btn-confirm {
      width: 420rpx;
      background-color: #1872ff;
      color: #ffffff;
    }
  }
}
</style>
